import {z} from 'zod' export type PlaylistInputFields = {description?: string | undefined, favorite?: boolean | undefined, name?: string | undefined, reference_id?: string | undefined, search?: string | undefined, search_syntax?: ('v1' | 'v2') | undefined, type?: ('EXPLICIT' | 'ACTIVATED_OLDEST_TO_NEWEST' | 'ACTIVATED_NEWEST_TO_OLDEST' | 'ALPHABETICAL' | 'PLAYS_TOTAL' | 'PLAYS_TRAILING_WEEK' | 'START_DATE_OLDEST_TO_NEWEST' | 'START_DATE_NEWEST_TO_OLDEST') | undefined, video_ids?: Array | undefined}; export type PatchApiV1AccountsAccountIdPlaylistsPlaylistIdArgs = {account_id: string, playlist_id: string, 'Content-Type': string, Authorization: string, body: PlaylistInputFields}; export type PatchApiV1AccountsAccountIdPlaylistsPlaylistIdOptions = {baseUrl?: string | undefined, BCOAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const playlist = z.object({account_id: z.string().optional(), created_at: z.string().optional(), description: z.string().max(255).optional(), favorite: z.boolean().optional(), id: z.string().optional(), name: z.string().max(255).optional(), reference_id: z.string().optional(), search: z.string().optional(), state: z.enum(["READY", "UPDATING"]).optional(), type: z.enum(["EXPLICIT", "ACTIVATED_OLDEST_TO_NEWEST", "ACTIVATED_NEWEST_TO_OLDEST", "ALPHABETICAL", "PLAYS_TOTAL", "PLAYS_TRAILING_WEEK", "START_DATE_OLDEST_TO_NEWEST", "START_DATE_NEWEST_TO_OLDEST"]).optional(), updated_at: z.string().optional(), video_ids: z.array(z.string()).optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Update Playlist * * PATCH /v1/accounts/{{account_id}}/playlists/{{playlist_id}} */ export const patchApiV1AccountsAccountIdPlaylistsPlaylistId = async (args: PatchApiV1AccountsAccountIdPlaylistsPlaylistIdArgs, options?: PatchApiV1AccountsAccountIdPlaylistsPlaylistIdOptions) => { const {baseUrl = "https://cms.api.brightcove.com", fetch: fetchFn = fetch, BCOAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (BCOAuth2 !== undefined) headers.set('authorization', `Bearer ${BCOAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/accounts/${encodeURIComponent(String(args['{account_id']))}}/playlists/${encodeURIComponent(String(args['{playlist_id']))}}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(playlist, await res.json()) };